#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void menu(void)
{
	printf("******************************\n");
	printf("******1.play******0.exit******\n");
	printf("***********请选择：>***********\n");
	printf("******************************\n");
}
void game(void)
{
	int a = rand() % 100 + 1;
	int guess = 0;
	int count = 5;
	printf("开始游戏！\n");
	while (count)
	{	
		printf("还剩%d次机会！\n", count);
		printf("请输入：>");
		scanf("%d", &guess);
		if (guess < a)
		{
			printf("猜小了！\n");
			count--;
		}
		else if (guess > a)
		{
			printf("猜大了！\n");
			count--;
		}
		else
		{
			printf("恭喜你，猜对了！\n");
			break;
		}
	}
	if (count == 0) 
	{
		printf("很遗憾！机会用光了！正确数字是%d!\n",a);
	}
}
int main()
{
	int input = 0;
	srand((unsigned int)time(NULL));
	do {
		menu();	
		scanf("%d", &input);
		switch (input)
			{
			case 0:
				printf("已退出！\n");
				break;
			case 1:
				game();
				break;
			default:
				printf("请输入正确的数字！\n");
				break;
			}
	} while (input);
	return 0;
}